********************************************************************************************************************************
***   Replication file for:                                                                                                  ***
***   Braun, S. T. and Stuhler, J. (2024). The Economic Consequences of Being Widowed by War: A Life-Cycle Perspective.	     ***
***	  Journal of Public Economics                                                                                            ***
***   							                                                                                             ***
***   ---   Main Do-File   ---   																							 ***
***	  --- 	German Life History Study (GHS)                                                                                  ***
***
***   Software:
***   Analyses run on Windows using Stata version 16 
***
***   Notes: 
***	  Data are stored in /data
***   Tables are outputted to /results/tables
***   Figures are outputted to /results/figures
***   To perform, a clean run delete the following folders: /results, /processed
***
***
********************************************************************************************************************************


*** Users must define global macro to point to the folder that contains the main do file
global widowsghs ""

* Confirm that the global for the project root directory was defined
assert !missing("$widowsghs")

* Initialize log
clear
set more off
cap mkdir "$widowsghs/scripts/logs"
cap log close
local datetime : di %tcCCYY.NN.DD!-HH.MM.SS `=clock("$S_DATE $S_TIME", "DMYhms")'
local logfile "$widowsghs/scripts/logs/`datetime'.log.txt"
log using "`logfile'", text

* Configure Stata's library environment and record system parameters
run "$widowsghs/scripts/programs/_config.do"

* Stata version control
version 18

* Create directories for output files
cap mkdir "$widowsghs/processed"
cap mkdir "$widowsghs/processed/intermediate"
cap mkdir "$widowsghs/results"
cap mkdir "$widowsghs/results/figures"
cap mkdir "$widowsghs/results/tables"

* Run project analysis
*do "$widowsghs/scripts/_install_stata_packages.do"
do "$widowsghs/scripts/1-preparation-ghs.do"
do "$widowsghs/scripts/2-analysis-ghs.do"

* End log
di "End date and time: $S_DATE $S_TIME"
log close

exit